package A01;


import java.util.Scanner;

//动态规划求最大的子数组
public  class D0502 {
    public static void main (String[] args) {
        Scanner Scan=new Scanner (System.in);
        int n=Scan.nextInt ();

        int[] arr=new int[n];
        for (int i = 0; i < n; i++) {
            arr[i]=Scan.nextInt ();
        }

        System.out.println (Max(n,arr));

    }

    private static int GetMax(int a,int b){
        return a>b?a:b;
    }

    private static int Max(int n,int[] arr){
        int current=arr[0];
        int max=arr[0];

        for (int i = 1; i < n; i++) {
            current=GetMax (arr[i],arr[i]+current);
            if(max<current)max=current;
        }

        return max;

    }

}
